<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>19 - 百度地图</title>
    <script src="http://api.map.baidu.com/api?v=2.0&ak=3LiphISVhEplmviL7E7ChfaaBkPW7EGp"></script>
    <script src="../lib/jQuery/jquery-3.6.0.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #map {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<div id='map'></div>
<script>
    $(document).ready(() => {
        let map = new BMap.Map('map');
        map.centerAndZoom('广东', 15);
        map.disableDoubleClickZoom();

        let _dom = $('<div>');
        let size = map.getSize();
        $(_dom).css({
            position: 'absolute',
            width: `${size.width}px`,
            height: `${size.height}px`,
            background: 'rgba(255,0,0,0.0)',
            cursor: 'crosshair'
        });
        $(map.getPanes().floatPane).append(_dom);

        _dom.on('click', evt => {
            // const centerPixel = map.getCenter();
            // console.log(centerPixel);
            const pixel = new BMap.Pixel(evt.offsetX, evt.offsetY);
            // console.log(evt);
            // console.log(pixel, evt.clientX, evt.clientY, evt.offsetTop, evt.offsetLeft);
            // const point = map.pixelToPoint(pixel);
            const point = map.overlayPixelToPoint(pixel);
            console.log(point);
            const marker = new BMap.Marker(point);
            map.addOverlay(marker);
            // console.log(evt);
            setTimeout(() => {
                map.setCenter(point);
            }, 3000);
        });

    });
</script>
</body>
</html>